package com.xjl.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.xjl.dao.WebDao;
import com.xjl.demo.Admin;
import com.xjl.demo.WebInfo;
import com.xjl.util.DBUtil;

public class WebDaoImpl implements WebDao{

	@Override
	public WebInfo SelectWebInfoDao() {
		Connection conn = null;
		PreparedStatement stmt = null;
		ResultSet rs = null;
		WebInfo webinfo = null;
		//进行查询数据库
		String sql = "select * from webinfo ";
		try {
			conn = DBUtil.getConnection();
			stmt = conn.prepareStatement(sql);
			rs = stmt.executeQuery();
			//返回查询结果集
			if(rs.next()){
				webinfo =new WebInfo();
				webinfo.setId(rs.getInt("id"));
				webinfo.setTitle(rs.getString("title"));
				webinfo.setLogo(rs.getString("logo"));
				webinfo.setDns(rs.getString("dns"));
				webinfo.setDes(rs.getString("des"));
				webinfo.setName(rs.getString("name"));
				webinfo.setPhone(rs.getString("phone"));
				webinfo.setQq(rs.getString("qq"));
				webinfo.setEmail(rs.getString("email"));
				webinfo.setAddress(rs.getString("address"));
				webinfo.setBinfo(rs.getString("binfo"));
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally{
			//关闭结果集
			DBUtil.close(rs, stmt, conn);
		}
	
		return webinfo;
		
	}

	@Override
	public int UpdateWebInfoDao(WebInfo info) {
		Connection conn = null;
		PreparedStatement stmt = null;
		int index=0;
		try {
			conn = DBUtil.getConnection();
			String sql = "update webinfo set title=?,logo=?,dns=?,des=?,name=?,phone=?,qq=?,email=?,address=?,binfo=? where id=?  ";
			stmt = conn.prepareStatement(sql);
			stmt.setString(1, info.getTitle());
			stmt.setString(2,info.getLogo());
			stmt.setString(3,info.getDns());
			stmt.setString(4,info.getDes());
			stmt.setString(5,info.getName());
			stmt.setString(6,info.getPhone());
			stmt.setString(7,info.getQq());
			stmt.setString(8,info.getEmail());
			stmt.setString(9,info.getAddress());
			stmt.setString(10,info.getBinfo());
			stmt.setInt(11,info.getId());
			index=stmt.executeUpdate();
		} catch (Exception e) {
			e.printStackTrace();
		}finally{
			DBUtil.close(stmt, conn);
		}
		return index;
	}

	
}
